package com.kuang.lock;

/**
 * @author Administrator
 * @date 2021/5/28 15:32
 * Description:可重入锁 Synchronized版
 */
public class Demo01 {
    //Synchronized 默认是非公平锁 支持可重入锁
    public static void main(String[] args) {
        Phone phone = new Phone();
        new Thread(()->{
            phone.sms();
        }, "A").start();

        new Thread(()->{
            phone.sms();
        }, "B").start();
    }
}

class Phone {
    public synchronized void sms() {
        System.out.println(Thread.currentThread().getName()+" sms");
        call(); //这里也有锁
    }

    public synchronized void call() {
        System.out.println(Thread.currentThread().getName()+" call");
    }
}
